//
//  InputItemTextField.m
//  QianYan
//
//  Created by jay on 2020/7/21.
//  Copyright © 2020 jay. All rights reserved.
//

#import "InputItemTextField.h"

@interface InputItemTextField ()
{
}
@property (nonatomic, assign) CGFloat leftViewMargin;
@property (nonatomic, assign) CGFloat rightViewMargin;
@property (nonatomic, assign) CGFloat textLeftMargin;
@property (nonatomic, assign) CGFloat textRightMargin;

@end

@implementation InputItemTextField

- (id)initWithFrame:(CGRect)frame
     leftViewMargin:(CGFloat )leftViewMargin
    rightViewMargin:(CGFloat )rightViewMargin
     textLeftMargin:(CGFloat )textLeftMargin
    textRightMargin:(CGFloat )textRightMargin
{
    self = [super initWithFrame:frame];
    if (self) {
        self.leftViewMargin = leftViewMargin;
        self.rightViewMargin = rightViewMargin;
        self.textLeftMargin = textLeftMargin;
        self.textRightMargin = textRightMargin;
    }
    return self;
}

#pragma mark - OverWrite

//UITextField leftView左间距
- (CGRect)leftViewRectForBounds:(CGRect)bounds
{
    CGRect iconRect = [super leftViewRectForBounds:bounds];
    iconRect.origin.x += self.leftViewMargin; //向右边偏leftViewMargin
    return iconRect;
}

//UITextField rightView右间距
- (CGRect)rightViewRectForBounds:(CGRect)bounds
{
    CGRect iconRect = [super rightViewRectForBounds:bounds];
    iconRect.origin.x -= self.rightViewMargin; //向左边偏rightViewMargin
    return iconRect;
}

//UITextField 文字与输入框的距离
- (CGRect)textRectForBounds:(CGRect)bounds
{
    return CGRectMake(self.textLeftMargin, bounds.origin.y, bounds.size.width-self.textLeftMargin-self.textRightMargin, bounds.size.height);
}

//控制文本的位置
- (CGRect)editingRectForBounds:(CGRect)bounds
{
    return CGRectMake(self.textLeftMargin, bounds.origin.y, bounds.size.width-self.textLeftMargin-self.textRightMargin, bounds.size.height);
}

@end
